import lang from 'element-plus/lib/locale/lang/zh-cn'
import 'dayjs/locale/zh-cn'
import 'element-plus/packages/theme-chalk/src/base.scss'

import {
  locale,
  ElInfiniteScroll,
  ElLoading,
  ElMessage,
  ElMessageBox,
  ElNotification,
  ElContainer,
  ElIcon,
  ElPopper,
  ElAside,
  ElHeader,
  ElMain,
  ElScrollbar,
  ElMenu,
  ElSubmenu,
  ElMenuItem,
  ElTable,
  ElTableColumn,
  ElButton,
  ElTag,
  ElForm,
  ElFormItem,
  ElInput,
  ElDatePicker,
  ElPagination,
  ElSwitch,
  ElDialog,
  ElRadio,
  ElRadioGroup,
  ElOption,
  ElSelect,
  ElBreadcrumb,
  ElBreadcrumbItem,
  ElPopover,
  ElCascader
} from 'element-plus'

const components = [
  ElIcon,
  ElPopper,
  ElContainer,
  ElAside,
  ElHeader,
  ElMain,
  ElScrollbar,
  ElMenu,
  ElSubmenu,
  ElMenuItem,
  ElTable,
  ElTableColumn,
  ElButton,
  ElTag,
  ElForm,
  ElFormItem,
  ElInput,
  ElDatePicker,
  ElPagination,
  ElSwitch,
  ElDialog,
  ElRadio,
  ElRadioGroup,
  ElOption,
  ElSelect,
  ElBreadcrumb,
  ElBreadcrumbItem,
  ElPopover,
  ElCascader
]

const plugins = [
  ElInfiniteScroll,
  ElLoading,
  ElMessage,
  ElMessageBox,
  ElNotification
]

// 设置语言
locale(lang)

export default {
  install: app => {
    // 全局设置Size
    app.config.globalProperties.$ELEMENT = { size: 'small' }
    // Element Plus 注册
    components.forEach(component => {
      app.component(component.name, component)
    })
    plugins.forEach(plugin => {
      app.use(plugin)
    })
  }
}
